package com.lvmama.system.controller;

import javax.servlet.http.HttpServletRequest;

import com.lvmama.entity.system.Config;
import com.lvmama.entity.system.SysUser;
import org.springframework.beans.factory.annotation.Value;

import java.util.ArrayList;
import java.util.List;

public class BaseController {

	@Value("${microServiceId}")
	private String microServiceId;
	/**
	 * 获取Session中保存的当前User Info
	*/
	public SysUser getCurrentUser(HttpServletRequest request){
		SysUser currentUser= (SysUser)request.getSession().getAttribute("currentUser");
		if(currentUser==null){
			currentUser = new SysUser();
		}
		return currentUser;
	}

	/*
	获取所有sysCode
	 */
	public List<String> getAllSysCode(List<Config> configList){
		List<String> sysCodeList = new ArrayList<String>();
		for(Config config : configList){
			sysCodeList.add(config.getSyscode());
		}
		sysCodeList.add(microServiceId);

		return sysCodeList;
	}
}
